package com.jimmy.tx.dao.impl;

import com.jimmy.tx.dao.LogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/**
 * @version 1.0
 * @ ClassName LogDaoImpl
 * <p> TODO
 * @ author JIMMY
 * @ Date 2020/11/8 0008 下午 9:51
 */
@Repository
public class LogDaoImpl extends JdbcDaoSupport implements LogDao {
    @Autowired
    public LogDaoImpl(DataSource dataSource){
        setDataSource(dataSource);
    }
    public void insertLog(final int type, final String content) {
        this.getJdbcTemplate().update( " insert into log(type,content,create_time) values(?,?,?) " , new  PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setInt(1,type);
                ps.setString(2,content);
                ps.setObject(3,new Date());
            }
        } );
    }
}
